<template>
	<view>
		<view class="pub-box">
				<view class="pub-box-bd">
					<view class="weui-cell weui-cell_input">
						<view class="weui-cell__hd">
							<view class="weui-label">
								所在医院
							</view>
						</view>
						<view class="weui-cell__bd">
							
						</view>
						<view class="weui-cell__ft weui-cell__ft_in-access">
							<picker 
								@change="onHisChange" 
								:value="curHospital.id" 
								:range="hospitals"
								range-key ="name"
							>
								<input 
									type="text"
									:disabled="true"
									placeholder="请选择要就诊的医院"
									:value="curHospital.name"
									placeholder-class="vp-placeholder"
								/>
							</picker>
						</view>
					</view>
					<view class="weui-cell weui-cell_input">
						<view class="weui-cell__hd">
							<view class="weui-label">
								服务时间
							</view>
						</view>
						<view class="weui-cell__bd">
							
						</view>
						<view class="weui-cell__ft weui-cell__ft_in-access">
							<view>
								<dtPicker
									@dtPickerChanged="onStartTimeChanged"
									:timestamp = "formData.starttime"
									placeholder="请选择期望服务时间"
								></dtPicker>
							</view>
						</view>
					</view>
					
					<view class="weui-cell" @click="onAddressChange">
						<view class="weui-cell__hd">
							<view class="weui-label">收件信息</view>
						</view>
						<view class="weui-cell__bd"></view>
						<view class="weui-cell__ft weui-cell__ft_in-access">
						    <input 
								class="weui-input" 
								disabled
								style="text-align: right"
						        placeholder-class="vp-placeholder"
								placeholder="请选择收件信息" 
								:value="formData.address.userName ?
								formData.address.userName + '('+formData.address.cityName+formData.address.countyName+')':''" />
						</view>
					</view>
					
					<view class="weui-cell">
						<view class="weui-cell__hd">
							<view class="weui-label">联系电话</view>
						</view>
						<view class="weui-cell__bd"></view>
						<view class="weui-cell__ft">
							<view>
								<input
									v-model="formData.tel"
									placeholder="请填写联系电话"
									placeholder-class="vp-placeholder"
								/>
							</view>
						</view>
					</view>
				</view>
			</view>
		
			<view class="pub-box">
			    <view class="pub-box-tt">服务需求</view>
			    <view class="pub-box-bd">
			        <view class="weui-cell weui-cell_input">
			            <view class="weui-cell__bd">
			                <textarea name="demand" auto-height placeholder="如有其他服务要求请在此填写..."
			                    placeholder-class="vp-placeholder" style="min-height: 150rpx" v-model="formData.demand" />
			            </view>
			        </view>
			    </view>
			</view>
			
			<SubmitOrder
				:service="service"
				:curHospital ="curHospital"
				:formData = "formData"
			/>
	</view>
</template>

<script>
	import SubmitOrder from './submit.vue'
	export default {
		components:{SubmitOrder},
		props:["service","hospitals","curHospital"],
		data() {
			return {
				//订单数据
				formData:{
					//服务时间
					starttime:'',
					//收件信息
					address:{
						cityName: "",
						countyName: "",
						detailInfo: "",
						userName: ""
					},
					//联系电话
					tel:'',
					//服务需求
					demand:''
				}
			}
		},
		methods: {
			//改变医院的数据
			onHisChange(e){
				this.$emit("update:curHospital",this.hospitals[e.detail.value])
			},
			//修改日期后的回调
			onStartTimeChanged(e){
				console.log(e)
				this.formData.starttime = e.detail.value
			},
			//选择就诊人
			onClientChange(){
				uni.navigateTo({
					url:'../clients/index?act=select'
				})
				//创建监听全局自定义事件，获取就诊人name
				uni.$on("clientName",({client})=>{
					this.clientName = client.name
				})
			},
			//改变地址的回调
			async onAddressChange(){
				try{
				  const res = await uni.chooseAddress()
				  this.formData.address.cityName = res.cityName
				  this.formData.address.countyName = res.countyName
				  this.formData.address.detailInfo = res.detailInfo
				  this.formData.address.userName = res.userName
				}catch(err){
					console.log(err)
				}
			},
			
			
		}
	}
</script>

<style>

</style>
